﻿using System;
using System.Collections.Generic;
using System.Text;
using Manso.cBot.Common;

namespace Manso.cBot.DefaultModules.Core
{
    public class AclAddCommand : ICommand
    {
        private ListenToEnum _listenTo;
        private string _command;
        private string _help;
        private string _usage;
        private AccessControlLevel _accessLevel;

        public AclAddCommand()
        {
            _listenTo = ListenToEnum.Tell;
            _command = "AclAdd";
            _help = "Add or change, if exists, the access control level of a character to cBot";
            _usage = "acladd character_name guest|basic|advance|owner";
            _accessLevel = AccessControlLevel.Owner;
        }

        public ListenToEnum ListenTo
        {
            get { return _listenTo; }
        }

        public string Command
        {
            get { return _command; }
        }

        public string Help
        {
            get { return _help; }
        }

        public string Usage
        {
            get { return _usage; }
        }

        public AccessControlLevel AccessLevel
        {
            get { return _accessLevel; }
        }

        public void ExecuteCommand(string[] args, string executedBy, ListenToEnum listenTo)
        {
            if (args.Length != 2 || args[0].Length <= 0 || args[1].Length <= 0)
            {
                cBotContext.Instance.SendPrivateMessage(executedBy,
                                                        "Invalid arguments, try help acladd for usage information");
                return;
            }

            try
            {
                cBotContext.Instance.AccessControl.Add(args[0], args[1]);   
                cBotContext.Instance.SendPrivateMessage(executedBy, "User added or changed succefully");
            }
            catch (ArgumentOutOfRangeException)
            {
             cBotContext.Instance.SendPrivateMessage(executedBy, "The level that you typed not exists. Try guest or basic or advance or owner.");   
            }
            catch (Exception)
            {
                cBotContext.Instance.SendPrivateMessage(executedBy, "Can't execute command. Unknown error");
            }
            
        }
    }
}
